<template>
    <el-row>
        <div class="recommend" ref="recommend">
            <el-row>
                <el-row class="recommend-item" 
                ref="recoItem"
                @mouseover.native="showRank(index)" 
                @mouseout.native="hideRank(index)"
                v-for="(item,index) in recommendCityList" :key="index">
                    <i></i>
                    <span class="type">{{item.type}}</span>
                </el-row>
            </el-row>
            <el-row class="rank" v-show="rankShow" 
                v-if="recommendCityList.length > 0" 
                @mouseover.native="showRank(rankIndex)"
                @mouseout.native="hideRank(rankIndex)"
                >
                <el-row class="rank-item" v-for="(item,num) in recommendCityList[rankIndex].children" :key="num"><span>{{num + 1}}</span><b>{{item.city}}</b><em>{{item.desc}}</em></el-row>
            </el-row>
        </div>
        <el-row class="recommend-city">
            <el-row class="title">推荐城市</el-row>
            <el-row class="pic">
                <img src="/images/pic_sea.jpeg" alt="">
            </el-row>
        </el-row>
    </el-row>
</template>

<script>
export default {
    data(){
        return{
            rankShow:false,
            rankIndex:0,
            recommendCityList:[]
        }
    },
    methods:{
        showRank(index){
            this.rankIndex = index;
            this.$refs.recommend.children[0].children[index].style.color = '#FFA000';
            this.$refs.recommend.children[0].children[index].children[0].style.opacity = '1';
            this.$refs.recommend.children[0].children[index].children[1].style.color = '#FFA000';
            this.rankShow = true;
        },
        hideRank(index){
            this.rankIndex = index;
            this.$refs.recommend.children[0].children[index].style.color = '#999';
            this.$refs.recommend.children[0].children[index].children[0].style.opacity = '0';
            this.$refs.recommend.children[0].children[index].children[1].style.color = '#000';
            this.rankShow = false;
        },
        loadRecommendCity(){
            this.$axios({
               url:'/posts/cities'
            }).then(res => {
                this.recommendCityList = res.data.data;
            })
        }
    },
    mounted(){
        this.loadRecommendCity();
    }
}
</script>

<style lang="less" scoped>
.recommend{
    position: relative;
    box-sizing: border-box;
    width:100%;
    height: 160px;
    border:1px solid #DDDDDD;
    border-bottom: 0;
    .recommend-item{
        position: relative;
        height: 40px;
        line-height: 35px;
        padding-left: 19px;
        color: #999;
        cursor: pointer;
        border-bottom:1px solid #DDDDDD;
        .type{
            font-size: 14px;
            color: #000;
        }
        i{
            position: absolute;
            right:-1px;
            top:0;
            width:1px;
            height: 40px;
            z-index:100;
            background-color: #fff;
            opacity:0;
        }
        &::after{
            content:'';
            width:10px;
            height: 10px;
            border-top: 1px;
            border-right: 1px;
            border-top-style: solid;
            border-right-style: solid;
            // 继承父盒子颜色
            border-color: inherit;
            // border-top: 1px solid inherit;
            // border-right: 1px solid inherit;
            transform: rotate(45deg);
            position: absolute;
            right: 20px;
            top: 15px;
        }
    }
    .rank{
        position: absolute;
        left:260px;
        top:-1px;
        width: 350px;
        height: 202px;
        z-index:99;
        padding:8px 0 8px 18px;
        border:1px solid #DDDDDD;
        background-color: #fff;
        // 利用父margin
        margin-left: -2px;
        .rank-item{
            line-height: 32px;
            span{
                font-size: 22px;
                color: #FFA000;
                font-style:italic;
                font-weight: 550;
            }
            b{
                margin:0 14px 0 16px;
                font-weight: 400;
                font-size: 14px;
                color: #FFA000;
                &:hover{
                   text-decoration: underline;
                }
            }
            em{
                font-style: normal;
                font-size: 14px;
                color: #999999;
                &:hover{
                   text-decoration: underline;
                }
            }
        }
    }
}
.recommend-city{
    .title{
        height: 40px;
        line-height: 40px;
        margin-top: 12px;
        font-size: 16px;
        border-bottom: 1px solid #DDDDDD;
    }
    .pic{
        width:100%;
        margin-top: 10px;
        img{
            width:100%;
        }
    }
}
</style>